package com.raycloud.dingtalk.starter.autoconfigure;


import cn.hutool.core.util.StrUtil;
import com.raycloud.dingtalk.starter.context.CommandListener;
import com.raycloud.dingtalk.starter.prop.DingTalkProp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
@EnableConfigurationProperties(DingTalkProp.class)
@ComponentScan("com.raycloud")
//@ConditionalOnProperty(prefix = DingTalkProp.DINGTALK_PREFIX, name = "enable", havingValue = "true")
public class DingtalkAutoConfiguration {

    @Autowired
    private DingTalkProp prop;

    /**
     * 校验mq基本的参数,后期扩展
     */
    @PostConstruct
    public void checkConfigFileExists() {

        String dingToken = prop.getDingToken();
        if (StrUtil.isEmpty(dingToken)) {
            throw new IllegalArgumentException("please add config dingtalk.props: dingToken");
        }
    }

    @Bean
    public CommandListener CommandListener() {
        return new CommandListener();
    }

}
